package top.lingkang.potato.network.interceptor;

import com.dtflys.forest.exceptions.ForestRuntimeException;
import com.dtflys.forest.http.ForestRequest;
import com.dtflys.forest.http.ForestResponse;
import com.dtflys.forest.interceptor.Interceptor;
import top.lingkang.potato.StateManager;
import top.lingkang.potato.dto.ResponseResult;

/**
 * @author lingkang
 * @date 2021/9/19 14:16
 * @description
 */
public class AuthInterceptor implements Interceptor<ResponseResult> {

    @Override
    public boolean beforeExecute(ForestRequest request) {
        request.addHeader("token", StateManager.token);
        return true;
    }

    @Override
    public void onError(ForestRuntimeException e, ForestRequest forestRequest, ForestResponse forestResponse) {
        System.out.println(e);
    }

    @Override
    public void onSuccess(ResponseResult result, ForestRequest forestRequest, ForestResponse forestResponse) {
        System.out.println(result);
    }
}
